﻿
using System;
using System.Web;

namespace ns_AppManage
{
    public static class c_AppManage
    {
        private const String ONLINE_NUMBER = "ONLINE_NUMBER";
        private static Int32 INIT_NUMBER = 0;

        private static Boolean Put(String keyword, Object obj)
        {
            try
            {
                HttpContext.Current.Application[keyword] = obj;
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
        private static T Get<T>(String keyword)
        {
            return (T)HttpContext.Current.Application[keyword];
        }
        private static Boolean Del(String keyword)
        {
            try
            {
                HttpContext.Current.Application.Remove(keyword);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public static void InitOnlineNumber()
        { 
            Put(ONLINE_NUMBER,INIT_NUMBER);
        }
        public static void OnlineNumberIncrease()
        {
            Put(ONLINE_NUMBER, Get<Int32>(ONLINE_NUMBER) +1);
        }
        public static void OnlineNumberDecrease()
        {
            Put(ONLINE_NUMBER, Get<Int32>(ONLINE_NUMBER) - 1);
        }

        public static Int32 GetOnlineNumber()
        {
            return Get<Int32>(ONLINE_NUMBER);
        }

       
    }
}